package com.yanqu.road.server.cmd.marriage.crossworld;

import com.yanqu.road.entity.marriage.MarriageInfo;
import com.yanqu.road.logic.pb.MarriagePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.marriage.CrossUnionWorldMarriageMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

import java.util.List;

@Cmd(code = Protocol.C_CROSS_WORLD_MARRIAGE_REFRESH_APPLY_LIST, desc = "刷新全服联姻列表")
public class CrossWorldMarriageRefreshApplyCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        MarriageProto.MarriageRefreshServerApplyReqMsg reqMsg = MarriageProto.MarriageRefreshServerApplyReqMsg.parseFrom(packet.getBytes());
        int childSex = reqMsg.getChildSex();

        List<MarriageInfo> serverApplyList = CrossUnionWorldMarriageMgr.refreshServerApplyList(packet.getPlayerId(), serverId, childSex);
        MarriageProto.MarriageRefreshServerApplyRespMsg.Builder respMsg = MarriageProto.MarriageRefreshServerApplyRespMsg.newBuilder();
        respMsg.setRet(0);
        MarriageProto.MarriageApplyListMsg.Builder listMsg = MarriagePb.parseMarriageApplyListMsg(serverApplyList);
        respMsg.setDataList(listMsg);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_MARRIAGE_REFRESH_SERVER_APPLY_LIST, respMsg));
    }

    @Override
    public void sendData() {

    }
}
